
var server = {
	pingIntervalMillis : 5000,
    serverUrl : "./feed",

	init : function() {
		
		// Initial setup
		dojo.xhrGet( {
		        // The following URL must match that used to test the server.
		        url: this.serverUrl + "?cmd=setup", 
		        handleAs: "text",
		        
		        load: function(responseObject, ioArgs) {
		          alert("Received response : " + responseObject); 
		          return responseObject; 
		        },
		         
		        error: function(response, ioArgs) {		        	
          			alert("HTTP status code: ", ioArgs.xhr.status);
          			return response; 
          		}
		});
				
		// Starting ping
		stg.pingIntervalId = window.setInterval('server.pingCallback()', this.pingIntervalMillis);
	},

    pingCallback : function() {
    	alert('Callback!');
    }
}

var text = {
	popup : {
		popupCnt : 0,
		popupPattern : [60,50,40,30,20,20,20,20,20,20,30,40,50,60],		
		popupRow : null,
		popupCell : null, 
		popupText : null			
	},
	
	popupCallback : function() {
		this.popup.popupCnt ++;		
		this.popup.popupRow.style.height = this.popup.popupCnt * 2 + "px";	
		if(this.popup.popupCnt <= this.popup.popupPattern.length) {
			window.setTimeout("text.popupCallback()", this.popup.popupPattern[this.popup.popupCnt]);
		}
		else {
			this.popup.popupCell.innerHTML = this.popup.popupText;			
		}		
	},	
	
	popupText : function(tr, td, txt) {
		this.popup.popupCnt = 0;
		this.popup.popupRow = tr;
		this.popup.popupCell = td;
		this.popup.popupText = txt;
		this.popupCallback();
	},

	addText : function(text) {
		var table = window.frames.textFrame.document.getElementById("textTableEl");
		var tr = table.insertRow(0);
		tr.style.height = "1px";			
		var td = tr.insertCell(0);		
		td.className = "textCell";
		this.popupText(tr, td, text);		
	}
}

var images = {
	shotsPath : "img/shots/",
	shotsExt  : ".jpg",
				
	scroll : {
		scrollCnt : 0,
		scrollPattern : [40,30,20,10,5,10,20,30,40],
		scrollDirection : 1,
		scrollWindow : null	
	},
	
	showImage : function(src) {
		var theImg = window.parent.document.getElementById('dynamicImageEl');  
		theImg.src = src;
		theImg.style.display = "inline";		
	},
	
	hideImage : function() {
		var theImg = window.parent.document.getElementById('dynamicImageEl');  
		theImg.src = "";
		theImg.style.display = "none";			
	},

	addImage : function(index) {
		var table = window.frames.shotsFrame.document.getElementById("imageTableEl");
		var tr = table.rows[0];			
		var td = tr.insertCell(tr.cells.length);
		td.className = "imageCell";
		var largeImgSrc  = this.shotsPath + index + this.shotsExt;
		var smallImgSrc  = this.shotsPath + index + "_small" + this.shotsExt;	
		td.innerHTML = "<a href=\"javascript:images.showImage('" + largeImgSrc + "')\" class=\"imageLink\" ><img class=\"imageLink\" src=\"" + smallImgSrc + "\" /></a>";		
	},
	
	scrollLeft : function() {
		this.scroll.scrollCnt = 0;
		this.scroll.scrollDirection = -1;
		this.scroll.scrollWindow = window.frames.shotsFrame.window;	
		this.scrollBy();
	},
	
	scrollRight : function() {
		this.scroll.scrollCnt = 0;
		this.scroll.scrollDirection = 1;
		this.scroll.scrollWindow = window.frames.shotsFrame.window;	
		this.scrollBy();
	},
		
	scrollBy : function() {
		this.scrollCallback();
	},
		
	scrollCallback : function() {
		this.scroll.scrollWindow.scrollBy(this.scroll.scrollDirection * 5, 0);
		this.scroll.scrollCnt ++;	
		if(this.scroll.scrollCnt <= this.scroll.scrollPattern.length) {
			window.setTimeout("images.scrollCallback()", this.scroll.scrollPattern[this.scroll.scrollCnt]);
		}		
	}	
		
}



